package main

import (
	"log"
	"net"
	"math"
	"strconv"
	"google.golang.org/grpc"
	pb "helloworld/proto"
)

type StreamService struct {}

func (s *StreamService) ListValue(req * pb.SimpleRequest, srv pb.StreamServer_ListValueServer) error {
	for n := 0; n < 5; n++ {
		err := srv.Send(&pb.StreamResponse{
			StreamValue: req.Data + strconv.Itoa(n),
	})
	if err != nil {
		return err
	 }
	}
	return nil
}

const (
	Address string = ":8000"
	Network string = "tcp"
)

func main() {
	lis, err := net.Listen(Network,Address)
	if err != nil {
		log.Fatalf("failed to listen: %v",err)
	}

	s := grpc.NewServer(grpc.MaxRecvMsgSize(1024*1024*4),grpc.MaxSendMsgSize(math.MaxInt32))


	//pb.RegisterGreeterServer(s,&server{})
	pb.RegisterStreamServerServer(s,&StreamService{})

	//reflection.Register(s)

	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
